import { GET_COMMENTS, ADD_COMMENTS, DEL_COMMENTS } from './action-types';

const initComments = [{
    id: 1,
    content: '我翻开这历史,这历史没有年代, 只是歪歪斜斜的每页都写着"仁义道德"四个字, 我横竖睡不着, 仔细看了半夜, 才从字缝中看出字来, 满本都写着两个字"吃人"',
    user: '鲁迅'
}]
export const comments = (state = initComments, action) => {
    switch (action.type) {
        case GET_COMMENTS:
            return action.data;
            break;
        case ADD_COMMENTS:
            const arr = [...state];
            const id=state.length>0?state[0].id+1:1;
            arr.unshift({ id, ...action.data });
            return arr;
            break;
        case DEL_COMMENTS:
            return state.filter((item) => item.id !== action.data);
            break;
        default:
            return state;
    }
}